#ifndef __ASM330_H
#define __ASM330_H
#include "sys.h"
#include <stdbool.h>


extern u8 x;
#define ASM330LHH_PIN_CTRL                     0x02U
#define ASM330LHH_FIFO_CTRL1                   0x07U
#define ASM330LHH_FIFO_CTRL2                   0x08U
#define ASM330LHH_FIFO_CTRL3                   0x09U
#define ASM330LHH_FIFO_CTRL4                   0x0AU
#define ASM330LHH_COUNTER_BDR_REG1             0x0BU
#define ASM330LHH_COUNTER_BDR_REG2             0x0CU
#define ASM330LHH_INT1_CTRL                    0x0DU
#define ASM330LHH_INT2_CTRL                    0x0EU
#define ASM330LHH_WHO_AM_I                     0x0FU
#define ASM330LHH_CTRL1_XL                     0x10
#define ASM330LHH_CTRL2_G                      0x11
#define ASM330LHH_CTRL3_C                      0x12
#define ASM330LHH_CTRL4_C                      0x13U
#define ASM330LHH_CTRL5_C                      0x14U
#define ASM330LHH_CTRL6_G                      0x15U
#define ASM330LHH_CTRL7_G                      0x16U
#define ASM330LHH_CTRL8_XL                     0x17U
#define ASM330LHH_CTRL9_XL                     0x18U
#define ASM330LHH_CTRL10_C                     0x19U
#define ASM330LHH_ALL_INT_SRC                  0x1AU
#define ASM330LHH_WAKE_UP_SRC                  0x1BU
#define ASM330LHH_TAP_SRC                      0x1CU
#define ASM330LHH_D6D_SRC                      0x1DU
#define ASM330LHH_STATUS_REG                   0x1EU
#define ASM330LHH_OUT_TEMP_L                   0x20U
#define ASM330LHH_OUT_TEMP_H                   0x21U
#define ASM330LHH_OUTX_L_G                     0x22U
#define ASM330LHH_OUTX_H_G                     0x23U
#define ASM330LHH_OUTY_L_G                     0x24U
#define ASM330LHH_OUTY_H_G                     0x25U
#define ASM330LHH_OUTZ_L_G                     0x26U
#define ASM330LHH_OUTZ_H_G                     0x27U
#define ASM330LHH_OUTX_L_A                     0x28U
#define ASM330LHH_OUTX_H_A                     0x29U
#define ASM330LHH_OUTY_L_A                     0x2AU
#define ASM330LHH_OUTY_H_A                     0x2BU
#define ASM330LHH_OUTZ_L_A                     0x2CU
#define ASM330LHH_OUTZ_H_A                     0x2DU
#define ASM330LHH_FIFO_STATUS1                 0x3AU
#define ASM330LHH_FIFO_STATUS2                 0x3BU
#define ASM330LHH_TIMESTAMP0                   0x40U
#define ASM330LHH_TIMESTAMP1                   0x41U
#define ASM330LHH_TIMESTAMP2                   0x42U
#define ASM330LHH_TIMESTAMP3                   0x43U
#define ASM330LHH_INT_CFG0                     0x56U
#define ASM330LHH_INT_CFG1                     0x58U
#define ASM330LHH_THS_6D                       0x59U
#define ASM330LHH_INT_DUR2                     0x5AU
#define ASM330LHH_WAKE_UP_THS                  0x5BU
#define ASM330LHH_WAKE_UP_DUR                  0x5CU
#define ASM330LHH_FREE_FALL                    0x5DU
#define ASM330LHH_MD1_CFG                      0x5EU
#define ASM330LHH_MD2_CFG                      0x5FU
#define ASM330LHH_INTERNAL_FREQ_FINE           0x63U
#define ASM330LHH_X_OFS_USR                    0x73U
#define ASM330LHH_Y_OFS_USR                    0x74U
#define ASM330LHH_Z_OFS_USR                    0x75U
#define ASM330LHH_FIFO_DATA_OUT_TAG            0x78U
#define ASM330LHH_FIFO_DATA_OUT_X_L            0x79U
#define ASM330LHH_FIFO_DATA_OUT_X_H            0x7AU
#define ASM330LHH_FIFO_DATA_OUT_Y_L            0x7BU
#define ASM330LHH_FIFO_DATA_OUT_Y_H            0x7CU
#define ASM330LHH_FIFO_DATA_OUT_Z_L            0x7DU
#define ASM330LHH_FIFO_DATA_OUT_Z_H            0x7EU

//禁止IIC模式，只存在SPI模式 LPF1带宽可选
#define  ASM330_I2C_IF_DIS        0X04

//选择不同的陀螺量程
#define  FS_G_250dps      0X00 
#define  FS_G_500dps      0X04
#define  FS_G_1000dps     0X08
#define  FS_G_2000dps     0X0C
//选择不同的加速度量程
#define  ACCEL_FS_XL_2g   0X00
#define  ACCEL_FS_XL_4g   0X08
#define  ACCEL_FS_XL_8g   0X0C
#define  ACCEL_FS_XL_16g  0X04

//加计采样率
 #define ASM330LHH_XL_ODR_OFF     0X00
 #define ASM330LHH_XL_ODR_12Hz5   0X10
 #define ASM330LHH_XL_ODR_26Hz    0X20
 #define ASM330LHH_XL_ODR_52Hz    0X30
 #define ASM330LHH_XL_ODR_104Hz   0X40
 #define ASM330LHH_XL_ODR_208Hz   0X50
 #define ASM330LHH_XL_ODR_417Hz   0X60
 #define ASM330LHH_XL_ODR_833Hz   0X70
 #define ASM330LHH_XL_ODR_1667Hz  0X80
 #define ASM330LHH_XL_ODR_3333Hz  0X90
 #define ASM330LHH_XL_ODR_6667Hz  0XA0

//陀螺仪采样率
 #define ASM330LHH_GY_ODR_OFF     0X00
 #define ASM330LHH_GY_ODR_12Hz5   0X10
 #define ASM330LHH_GY_ODR_26Hz    0X20
 #define ASM330LHH_GY_ODR_52Hz    0X30
 #define ASM330LHH_GY_ODR_104Hz   0X40
 #define ASM330LHH_GY_ODR_208Hz   0X50
 #define ASM330LHH_GY_ODR_417Hz   0X60
 #define ASM330LHH_GY_ODR_833Hz   0X70
 #define ASM330LHH_GY_ODR_1667Hz  0X80
 #define ASM330LHH_GY_ODR_3333Hz  0X90
 #define ASM330LHH_GY_ODR_6667Hz  0XA0

//LPF1 bandwidth selection
  #define ASM330LHH_LPF1_FTYPE1           0X00
  #define ASM330LHH_LPF1_FTYPE2           0X01
	#define ASM330LHH_LPF1_FTYPE3           0X02
	#define ASM330LHH_LPF1_FTYPE4          	0X03
	#define ASM330LHH_LPF1_FTYPE5           0X04
	#define ASM330LHH_LPF1_FTYPE6           0X05
	#define ASM330LHH_LPF1_FTYPE7           0X06
	#define ASM330LHH_LPF1_FTYPE8           0X07
	
//Tigger mode selection 
 #define Trigger_mode_OFF                  0X00
 #define Edge_sensitive_trigger            0X80
 #define Level_sensitive_trigger           0X40
 #define Level_sensitive_latched           0X60
 #define Level_sensitive_FIFO              0XC0


//Accelerometer bandwidth 
 #define  LOW_Pass_ODR_DIV_4               0X00
 #define  LOW_Pass_ODR_DIV_10              0x20
 #define  LOW_Pass_ODR_DIV_20              0X40
 #define  LOW_Pass_ODR_DIV_45              0X60
 #define  LOW_Pass_ODR_DIV_100             0X80
 #define  LOW_Pass_ODR_DIV_200             0XA0
 #define  LOW_Pass_ODR_DIV_400             0XC0
 #define  LOW_Pass_ODR_DIV_800             0XE0              //LOW Pass Bandwidth 
 

 #define  High_Pass_ODR_DIV_4               0X14
 #define  High_Pass_ODR_DIV_10              0x34
 #define  High_Pass_ODR_DIV_20              0X54
 #define  High_Pass_ODR_DIV_45              0X74
 #define  High_Pass_ODR_DIV_100             0X94
 #define  High_Pass_ODR_DIV_200             0XB4
 #define  High_Pass_ODR_DIV_400             0XD4
 #define  High_Pass_ODR_DIV_800             0XF4           //High Pass Bandwidth
 
 #define  Deviece_Reset                     0X05
 #define  Decice_Conf                       0XE2
 //ASM330操作线
#define ASM330_CS_ACC_1  PCout(0)   //SPI1片选信号

#define ASM330_CS_ACC_2  PCout(1)   //SPI2片选信号

#define ASM330_CS_ACC_3  PCout(2)   //SPI3片选信号

#define ASM330_CS_ACC_4  PCout(3)   //SPI4片选信号






#define CS1          1
#define CS2          2
#define CS3          3
#define CS4          4


#define SPI_1             0x01
#define SPI_2             0x02
#define SPI_3             0x03
#define SPI_4             0x04


#define Enable      1
#define Disable     0

void Sensor_SPI_Init(void);
void CS_Disable(void);
void ASM330_Write_Reg(u8 reg,u8 value,u8 SPIx);
void ASM330_ChangeData_SPI1(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_ChangeData_SPI2(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_ChangeData_SPI3(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_ChangeData_SPI4(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_ChangeData_SPI5(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_ChangeData_SPI6(u8 *aBuf,u8 *bBuf,u8 IMU);
void ASM330_CS (u8 enable,u8 CSx);  //片选
u8 ASM330_Read_Reg(u8 reg,u8 SPIx);
u8 ASM330_RESET_SET(u8 deviece_reset,u8 decice_conf);
u8 ASM330_User_Ctrl(u8 iic_if_dis);
u8 ASM330_DataUpdate_FullScale_Set(u8 XL_update_set,u8 G_update_set,u8 XL_fullscale,u8 G_fullscale);
u8 ASM330_LPF1_bandwidth(u8 Trigger_mode, u8 LPF1_bandwidth);
u8 ASM330_LPF2_path_set(u8 high_pass_bandwidth);
u8 ASM330_Read_Buf(u8 reg,u8 *pBuf,u8 len,u8 SPIx);//读数据
u8 INT2_Update(u8 data_ready);
u8 Isenable(u8 flag);
u8 Dataready_Pulsed(u8 dataready_pulsed);

extern u8 statu1,statu2,statu3,statu4,statu5,statu6;


#endif
